package javaFeatures.src.TestFeature.oopcourse;

public class Draw {
    private int height;


    public Draw(int h) {
        if (h <= 3) {
            height = 3;
        } else {
            height = h;
        }
    }


    public void drawTriangle() {
        for (int i = 1; i <= height; i++) {
            for (int j = 1; j <= height - i; j++) {
                System.out.print(" ");
            }
            for (int k = 1; k <= 2 * i - 1; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }


    public void drawRectangle(int width) {
        for (int i = 1; i <= height; i++) {
            for (int j = 1; j <= width; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }


    public void drawSquare() {
        drawRectangle(height);
    }


    public void drawParallelogram(int offset) {
        for (int i = 1; i <= height; i++) {
            for (int j = 1; j <= offset; j++) {
                System.out.print(" ");
            }
            for (int k = 1; k <= height; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        Draw drawer = new Draw(5);

        System.out.println("绘制三角形:");
        drawer.drawTriangle();
        System.out.println();

        System.out.println("绘制矩形:");
        drawer.drawRectangle(8);
        System.out.println();

        System.out.println("绘制正方形:");
        drawer.drawSquare();
        System.out.println();

        System.out.println("绘制平行四边形:");
        drawer.drawParallelogram(2);
        System.out.println();
    }
}
